home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / x11 / lib / cursors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-29  |  3.7 KB  |  159 lines

  1. /*
  2.     CURSORS . C
  3. %
  4. % AUTHOR:    see included header files
  5. */
  6.  
  7. #include "function.h"
  8.  
  9. #include "circle.bitmap"
  10. #include "circle_mask.bitmap"
  11.  
  12. Cursor    circle_cursor, left_ptr_cursor, watch_cursor, cursor;
  13.  
  14. void
  15. set_window_cursor(window, cursor_type)
  16. Window    window;
  17. Cursor    cursor_type;
  18. {
  19.     XDefineCursor(Dpy, window, cursor_type);
  20.     XFlush(Dpy);
  21. }
  22.  
  23. void    set_watch_cursor(window)
  24. Window    window;
  25. {
  26.     set_window_cursor(window, watch_cursor);
  27. }
  28.  
  29. void    set_circle_cursor(window)
  30. Window    window;
  31. {
  32.     set_window_cursor(window, circle_cursor);
  33. }
  34.  
  35. void    set_left_ptr_cursor(window)
  36. Window    window;
  37. {
  38.     set_window_cursor(window, left_ptr_cursor);
  39. }
  40.  
  41. void
  42. get_cursors(window)
  43. Window window;
  44. {
  45.     if (!circle_cursor)
  46.         circle_cursor = XCreateFontCursor(Dpy, XC_circle);
  47.     if (!watch_cursor)
  48.         watch_cursor = XCreateFontCursor(Dpy, XC_watch);
  49.     if (!left_ptr_cursor)
  50.         left_ptr_cursor = XCreateFontCursor(Dpy, XC_left_ptr);
  51.  
  52.     if (circle_cursor == NULL) {
  53.     XColor    color_1, color_2;
  54.     Pixmap    source = XCreateBitmapFromData(Dpy, window, circle_bits,
  55.                 circle_width, circle_height),
  56.         mask = XCreateBitmapFromData(Dpy, window, circle_mask_bits,
  57.                 circle_width, circle_height);
  58.  
  59.         color_1.pixel = WhitePixel(Dpy, Screen);
  60.         color_1.red   = color_1.green = color_1.blue  = 0xffff;
  61.  
  62.         color_1.pixel = BlackPixel(Dpy, Screen);
  63.         color_2.red   = color_2.green = color_2.blue  = 0;
  64.         color_1.flags = color_2.flags = DoAll;
  65.  
  66.         circle_cursor = XCreatePixmapCursor(Dpy, source, mask,
  67.                     &color_1, &color_2,
  68.                     circle_x_hot, circle_y_hot);
  69.         XFreePixmap(Dpy, source);
  70.         XFreePixmap(Dpy, mask);
  71.     }
  72.     if (watch_cursor == NULL)
  73.         watch_cursor = circle_cursor;
  74.     if (left_ptr_cursor == NULL)
  75.         left_ptr_cursor = circle_cursor;
  76. }
  77.  
  78. /*=======================================
  79. %    Remove those non useful events.    %
  80. %    If no exposure_handle passed,    %
  81. %    exposure events will be saved.    %
  82. =======================================*/
  83. void
  84. Delay_Clear(aw, exp_hd, imgp, imgs, fdelay)
  85. AnyWindow*    aw;
  86. int    (*exp_hd)();
  87. Image    **imgp;
  88. {
  89. int    dl;
  90.     while (--fdelay)    {
  91.     while (ImageEvent(aw, ButtonPressMask))
  92.         XBell(aw->dpy, 50);
  93.     RemoveImageEvent(aw, PointerMotionMask);
  94.     if (exp_hd && ImageEvent(aw, ExposureMask)) {
  95.     register Image    *img=NULL;
  96.     register int    i;
  97.         if (imgp && (i =
  98.         WhichImage(aw->event->xany.window, imgp, imgs)) >= 0)
  99.         img = imgp[i];
  100.         exp_hd(aw->event, img);
  101.     }
  102.     }
  103. }
  104.  
  105. void
  106. FlushingCursor(aw, exp_hd, imgp, imgs, x0, y0, cw, ch, fdelay, rev)
  107. AnyWindow*    aw;
  108. int    (*exp_hd)();
  109. Image    **imgp;
  110. {
  111. int    clear=0, show=0;
  112.  
  113.     if (fdelay < 4 || fdelay > 24)    fdelay = 15;
  114.     fdelay <<= 2;
  115.     do {
  116.     /* light up writing position cursor & flushing delay */
  117.         Delay_Clear(aw, exp_hd, imgp, imgs, fdelay);
  118.         if (!clear && !(show>>=1))    {
  119.             if (rev)
  120.             XSetFunction(aw->dpy, aw->gc, GXinvert);
  121.             XFillRectangle(aw->dpy, aw->win, aw->gc, x0, y0, cw, ch);
  122.             clear = fdelay;
  123.         }
  124.         XSetFunction(aw->dpy, aw->gc, GXcopy);
  125.         /*    erase writing position cursor    */
  126.         Delay_Clear(aw, exp_hd, imgp, imgs, fdelay);
  127.         if (!show && !(clear>>=1))    {
  128.             if (rev)
  129.             XSetFunction(aw->dpy, aw->gc, GXinvert),
  130.             XFillRectangle(aw->dpy, aw->win, aw->gc, x0, y0, cw, ch);
  131.             else    XClearArea(aw->dpy, aw->win, x0, y0, cw, ch, 0);
  132.             show = fdelay;
  133.         }
  134.         XSetFunction(aw->dpy, aw->gc, GXcopy);
  135.     } while (!ImageEvent(aw, KeyPressMask));
  136.  
  137.     if (clear)    /* clear cursor */
  138.         if (rev)
  139.         XSetFunction(aw->dpy, aw->gc, GXinvert),
  140.         XFillRectangle(aw->dpy, aw->win, aw->gc, x0, y0, cw, ch);
  141.         else    XClearArea(aw->dpy, aw->win, x0, y0, cw, ch, 0);
  142.  
  143.     XSetFunction(aw->dpy, aw->gc, GXcopy);
  144. }
  145.  
  146. void
  147. TopWindow(awin, use_unmap)
  148. AnyWindow*    awin;
  149. {
  150. if (use_unmap) {
  151.     XUnmapWindow(awin->dpy, awin->frame);
  152.     XMapWindow(awin->dpy, awin->frame);
  153. } else    {
  154.     XClearArea(awin->dpy, awin->win, 0, 0, 0, 0, True);
  155.     XRaiseWindow(awin->dpy, awin->frame);
  156. }
  157. XWindowEvent(awin->dpy, awin->win, ExposureMask, awin->event);
  158. }
  159.